package com.lee.goods;


import com.alibaba.dubbo.config.annotation.Service;
import com.lee.goods.api.IMallBrandService;
import com.lee.goods.entity.MallBrand;
import com.lee.goods.mapper.MallBrandMapper;
import com.lee.utils.StringUtils;
import com.github.pagehelper.Page;
import com.lee.page.PageDomain;
import com.lee.page.PageResult;
import com.lee.utils.Convert;
import org.springframework.beans.factory.annotation.Autowired;

import static com.github.pagehelper.page.PageMethod.startPage;

/**
 * 品牌 服务层实现
 * 
 * @author LiPengFei
 * @date 2018-10-05
 */
@Service
public class MallBrandServiceImpl implements IMallBrandService
{
	@Autowired
	private MallBrandMapper mallBrandMapper;

	/**
     * 查询品牌信息
     * 
     * @param brandId 品牌ID
     * @return 品牌信息
     */
    @Override
	public MallBrand selectMallBrandById(Long brandId)
	{
	    return mallBrandMapper.selectMallBrandById(brandId);
	}


	/**
     * 查询品牌列表
     * 
     * @param mallBrand 品牌信息
     * @return 品牌集合
     */
    @Override
    public PageResult selectMallBrandList(MallBrand mallBrand,PageDomain pageDomain) {
        startPage(pageDomain);
        Page<MallBrand> page = (Page<MallBrand>)mallBrandMapper.selectMallBrandList(mallBrand);
        return new PageResult(page.getTotal(),page.getResult());
    }

    /**
     * 新增品牌
     * 
     * @param mallBrand 品牌信息
     * @return 结果
     */
	@Override
	public int insertMallBrand(MallBrand mallBrand)
	{
	    return mallBrandMapper.insertMallBrand(mallBrand);
	}
	
	/**
     * 修改品牌
     * 
     * @param mallBrand 品牌信息
     * @return 结果
     */
	@Override
	public int updateMallBrand(MallBrand mallBrand)
	{
	    return mallBrandMapper.updateMallBrand(mallBrand);
	}
	
	/**
     * 保存品牌
     * 
     * @param mallBrand 品牌信息
     * @return 结果
     */
	@Override
	public int saveMallBrand(MallBrand mallBrand)
	{
	    Long brandId = mallBrand.getBrandId();
		int rows = 0;
		if (StringUtils.isNotNull(brandId))
        {
		    rows = mallBrandMapper.updateMallBrand(mallBrand);
		}
		else
        {
		    rows = mallBrandMapper.insertMallBrand(mallBrand);
		}
		return rows;
	}
	
	/**
     * 删除品牌对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
	@Override
	public int deleteMallBrandByIds(String ids)
	{
		return mallBrandMapper.deleteMallBrandByIds(Convert.toStrArray(ids));
	}
	
}
